package mirrormonkey.core.member;

import com.jme3.network.MessageConnection;

public final class SearchNamedKey extends SearchKey {

	private final String name;

	public SearchNamedKey(MessageConnection connection, Object[] parameters,
			String name) {
		super(connection, parameters);
		this.name = name;
	}

	@Override
	public final boolean equals(Object o) {
		if (!o.getClass().equals(PresentNamedKey.class)) {
			return false;
		}
		PresentNamedKey k = (PresentNamedKey) o;
		Object[] parameters = getParameters();
		if (k.name.equals(name) && k.parameterCount() == parameters.length) {
			for (int i = 0; i < parameters.length; i++) {
				Class<?> pc = k.data.interpreters[i].fetchClass(
						getConnection(), parameters[i]);
				if (pc != null
						&& !k.data.constr.getParameterTypes()[i]
								.isAssignableFrom(pc)) {
					return false;
				}
			}
		}
		return true;
	}
}
